/**
 * Created by Administrator on 2016-12-14.
 */


const http = require('http');

var iconv = require('iconv-lite');

var cheerio = require('cheerio');

http.get('http://www.laoguo5.com/zuixin/', (res) => {

    let rawData = '';
    res.on('data', (chunk) => rawData += iconv.decode(chunk,'gbk'));

    res.on('end', () => {

         console.log(rawData)
        //rawData = iconv.decode(rawData,'gbk');

        //console.log(`BODY: ${chunk}`);

        var $ = cheerio.load(rawData);

        //console.log($);

        var items =[];

        $('#con_xin_1 li a').each(function (i,element) {
            var $element = $(element);
            items.push({
                index: i,
                title: $element.attr('title'),
                href: $element.attr('href'),
                img: $element.find('img').attr('src')
            })
        })

        console.log(items);
    });
})

//http://www.laoguo5.com/zuixin/
/*var options = {
    hostname: 'www.laoguo5.com',
    path: '/zuixin/',
    timeout: 10000
}

var req = http.request(options,(res) => {
    console.log(`STATUS: ${res.statusCode}`);
    console.log(`HEADERS: ${JSON.stringify(res.headers)}`);
    console.log(res);
});

req.on('error', (e) => {
    console.log(`problem with request: ${e.message}`);
});*/

